﻿/*
 * tester: Guangyu Sun
 */
//unicode used in unit test"※€™⅛	♪"
//Chinese"福尔摩斯", Japanese"ホルムス"


using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AircraftBattleServer;

namespace ServerInterfaceTestProject
{
    /// <summary>
    /// Summary description for IGameEngineServiceTest1
    /// </summary>
    public partial class IGameEngineServiceTest
    {
        /// <summary>
        ///A test for IsAdmin
        ///</summary>
        [TestMethod()]
        public void IsAdminTest1()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value

            string username = "martin";
            bool expected = true;
            bool actual;
            actual = target.IsAdmin(username);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for IsAdmin
        ///</summary>
        [TestMethod()]
        public void IsAdminTest2()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value

            string username = "sun";
            bool expected = false;
            bool actual;
            actual = target.IsAdmin(username);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for IsAdmin
        ///</summary>
        [TestMethod()]
        public void IsAdminTestA1()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "admin";
            bool expected = true;
            bool actual = false;
            try
            {
                target.IsAdmin(username);
            }
            catch (Exception e)
            {
                if (e.Message == "User '" + username + "' does not exist.")
                    actual = true;
            }
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for IsAdmin
        ///</summary>
        [TestMethod()]
        public void IsAdminTestA2()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value

            string username = "root";
            bool expected = true;
            bool actual = false;
            try
            {
                target.IsAdmin(username);
            }
            catch (Exception e)
            {
                if (e.Message == "User '" + username + "' does not exist.")
                    actual = true;
            }
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for IsAdmin
        ///</summary>
        [TestMethod()]
        public void IsAdminTestB()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value

            string username = @"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            bool expected = true;
            bool actual = false;
            try
            {
                target.IsAdmin(username);
            }
            catch (Exception e)
            {
                if (e.Message == "User '" + username + "' does not exist.")
                    actual = true;
            }
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for IsAdmin
        ///</summary>
        [TestMethod()]
        public void IsAdminTestC()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value

            string username = "※€™⅛	♪";
            bool expected = true;
            bool actual = false;
            try
            {
                target.IsAdmin(username);
            }
            catch (Exception e)
            {
                if (e.Message == "User '" + username + "' does not exist.")
                    actual = true;
            }
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for IsAdmin
        ///</summary>
        [TestMethod()]
        public void IsAdminTestD1()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value

            string username = "福尔摩斯";
            bool expected = false;
            bool actual = target.IsAdmin(username);
          
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for IsAdmin
        ///</summary>
        [TestMethod()]
        public void IsAdminTestD2()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value

            string username = "ホルムス";
            bool expected = false;
            bool actual = target.IsAdmin(username);
            
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for CreateUser
        ///</summary>
        [TestMethod()]
        public void CreateUserTest()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "new";
            bool bexpected = false;
            bool bactual;
            bactual = target.IfUserExist(username);
            Assert.AreEqual(bexpected, bactual);

            target.CreateUser(username);

            bool expected = true;
            bool actual;
            actual = target.IfUserExist(username);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for CreateUser
        ///</summary>
        [TestMethod()]
        public void CreateUserTestA()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "sun";
            bool bexpected = true;
            bool bactual;
            bactual = target.IfUserExist(username);
            Assert.AreEqual(bexpected, bactual);

            target.CreateUser(username);

            bool expected = true;
            bool actual;
            actual = target.IfUserExist(username);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for CreateUser
        ///</summary>
        [TestMethod()]
        public void CreateUserTestB()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "";
            bool bexpected = false;
            bool bactual;
            bactual = target.IfUserExist(username);
            Assert.AreEqual(bexpected, bactual);

            bool expected = true;
            bool actual = false;
            try
            {
                target.CreateUser(username);
            }
            catch (Exception e)
            {
                if(e.Message == "Username cannot be empty")
                    actual = true;
            }

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for CreateUser
        ///</summary>
        [TestMethod()]
        public void CreateUserTestC()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = @"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            bool bexpected = false;
            bool bactual;
            bactual = target.IfUserExist(username);
            Assert.AreEqual(bexpected, bactual);

            bool expected = true;
            bool actual = false;

            try
            {
                target.CreateUser(username);
            }
            catch (Exception e)
            {
                if (e.Message == "Username must be less than 11 characters")
                    actual = true;
            }
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for CreateUser
        ///</summary>
        [TestMethod()]
        public void CreateUserTestD()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "※€™⅛	♪";
            bool bexpected = false;
            bool bactual;
            bactual = target.IfUserExist(username);
            Assert.AreEqual(bexpected, bactual);

            target.CreateUser(username);

            bool expected = true;
            bool actual;
            actual = target.IfUserExist(username);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for CreateUser
        ///</summary>
        [TestMethod()]
        public void CreateUserTestE1()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "福尔摩斯";
            bool bexpected = false;
            bool bactual;
            bactual = target.IfUserExist(username);
            Assert.AreEqual(bexpected, bactual);

            target.CreateUser(username);

            bool expected = true;
            bool actual;
            actual = target.IfUserExist(username);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for CreateUser
        ///</summary>
        [TestMethod()]
        public void CreateUserTestE2()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "ホルムス";
            bool bexpected = false;
            bool bactual;
            bactual = target.IfUserExist(username);
            Assert.AreEqual(bexpected, bactual);

            target.CreateUser(username);

            bool expected = true;
            bool actual;
            actual = target.IfUserExist(username);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for SetTeam
        ///</summary>
        [TestMethod()]
        public void SetTeamTest()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "sun";
            int team = 2;
            int uid = target.GetAircraftID(username);
            MapData mapdata = target.GetMapData();
            target.AddPlayer(username, uid);
            
            target.SetTeam(username, team);

            int expected = 2;
            int actual;
            lock (mapdata)
            {
                actual = mapdata.userList.Find(
                    delegate(User u)
                    {
                        return u.userName == username;
                    }
                    ).GetTeam();
            }
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for SetTeam
        ///</summary>
        [TestMethod()]
        public void SetTeamTestA()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "nonexist";
            int team = 2;
            MapData mapdata = target.GetMapData();

            bool expected = true;
            bool actual = false;

            try
            {
                int uid = target.GetAircraftID(username);
                target.AddPlayer(username, uid);
                target.SetTeam(username, team);

                lock (mapdata)
                {
                    mapdata.userList.Find(
                        delegate(User u)
                        {
                            return u.userName == username;
                        }
                        ).GetTeam();
                }
            }
            catch (Exception e)
            {
                actual = true;
            }
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for SetTeam
        ///</summary>
        [TestMethod()]
        public void SetTeamTestB()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "sun";
            int team = -1;
            MapData mapdata = target.GetMapData();

            bool expected = true;
            bool actual = false;

            try
            {
                int uid = target.GetAircraftID(username);
                target.AddPlayer(username, uid);
                target.SetTeam(username, team);

                lock (mapdata)
                {
                    mapdata.userList.Find(
                        delegate(User u)
                        {
                            return u.userName == username;
                        }
                        ).GetTeam();
                }
            }
            catch (Exception e)
            {
                actual = true;
            }
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for SetTeam
        ///</summary>
        [TestMethod()]
        public void SetTeamTestC()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "sun";
            int team = 0;
            MapData mapdata = target.GetMapData();

            bool expected = true;
            bool actual = false;

            try
            {
                int uid = target.GetAircraftID(username);
                target.AddPlayer(username, uid);
                target.SetTeam(username, team);

                lock (mapdata)
                {
                    mapdata.userList.Find(
                        delegate(User u)
                        {
                            return u.userName == username;
                        }
                        ).GetTeam();
                }
            }
            catch (Exception e)
            {
                actual = true;
            }
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for SetTeam
        ///</summary>
        [TestMethod()]
        public void SetTeamTestD()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "sun";
            int team = 100;
            MapData mapdata = target.GetMapData();

            bool expected = true;
            bool actual = false;

            try
            {
                int uid = target.GetAircraftID(username);
                target.AddPlayer(username, uid);
                target.SetTeam(username, team);

                lock (mapdata)
                {
                    mapdata.userList.Find(
                        delegate(User u)
                        {
                            return u.userName == username;
                        }
                        ).GetTeam();
                }
            }
            catch (Exception e)
            {
                actual = true;
            }
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for SetReady
        ///</summary>
        [TestMethod()]
        public void SetReadyTest1()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "sun";
            int ready = 0;

            int uid = target.GetAircraftID(username);
            MapData mapdata = target.GetMapData();
            target.AddPlayer(username, uid);

            target.SetReady(username, ready);

            int expected = 0;
            int actual;
            lock (mapdata)
            {
                actual = mapdata.userList.Find(
                    delegate(User u)
                    {
                        return u.userName == username;
                    }
                    ).GetReady();
            }
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for SetReady
        ///</summary>
        [TestMethod()]
        public void SetReadyTest2()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "sun";
            int ready = 1;

            int uid = target.GetAircraftID(username);
            MapData mapdata = target.GetMapData();
            target.AddPlayer(username, uid);

            target.SetReady(username, ready);

            int expected = 1;
            int actual;
            lock (mapdata)
            {
                actual = mapdata.userList.Find(
                    delegate(User u)
                    {
                        return u.userName == username;
                    }
                    ).GetReady();
            }
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for SetReady
        ///</summary>
        [TestMethod()]
        public void SetReadyTestA()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "sun";
            int ready = -1;
            MapData mapdata = target.GetMapData();
            bool expected = true;
            bool actual = false;

            try
            {
                int uid = target.GetAircraftID(username);

                target.AddPlayer(username, uid);

                target.SetReady(username, ready);

                lock (mapdata)
                {
                    mapdata.userList.Find(
                        delegate(User u)
                        {
                            return u.userName == username;
                        }
                        ).GetReady();
                }
            }
            catch (Exception e)
            {
                actual = true;
            }
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for SetReady
        ///</summary>
        [TestMethod()]
        public void SetReadyTestB()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "nonexist";
            int ready = 1;
            MapData mapdata = target.GetMapData();
            bool expected = true;
            bool actual = false;

            try
            {
                int uid = target.GetAircraftID(username);

                target.AddPlayer(username, uid);

                target.SetReady(username, ready);

                lock (mapdata)
                {
                    mapdata.userList.Find(
                        delegate(User u)
                        {
                            return u.userName == username;
                        }
                        ).GetReady();
                }
            }
            catch (Exception e)
            {
                actual = true;
            }
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for SetReady
        ///</summary>
        [TestMethod()]
        public void SetReadyTestC()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "";
            int ready = 1;
            MapData mapdata = target.GetMapData();
            bool expected = true;
            bool actual = false;

            try
            {
                int uid = target.GetAircraftID(username);

                target.AddPlayer(username, uid);

                target.SetReady(username, ready);

                lock (mapdata)
                {
                    mapdata.userList.Find(
                        delegate(User u)
                        {
                            return u.userName == username;
                        }
                        ).GetReady();
                }
            }
            catch (Exception e)
            {
                actual = true;
            }
            Assert.AreEqual(expected, actual);
        }
    }
}
